<template>
  <div class="login" style="-webkit-app-region: drag;">
    <div class="center">
      <h1><div class="logo"></div></h1>
      <form action="javascript:void(0)">
        <div class="inputLi">
          <input style="-webkit-app-region: no-drag;" type="text" class="user" v-model="user.username" placeholder="请输入用户名">
        </div>
        <div class="inputLi">
          <input style="-webkit-app-region: no-drag;" type="password" class="pwd" v-model="user.password" placeholder="请输入密码">
        </div>
        <div class="inputLi">
          <button type="button" @click="loginClick">登录</button>
        </div>
      </form>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
import qs from "qs";
import {ipcRenderer} from "electron";

export default {
  name: "Login",
  data(){
    return {
      user :{
        username:"",
        password:""
      }
    }
  },
  methods:{
    loginClick(){
      let _this = this;
      if(_this.user.username === ""){_this.$message.error('请输入用户名');return;}
      if(_this.user.password === ""){_this.$message.error('请输入密码');return;}
      request.post('/huodong/sj/el/login.php',{
        data:qs.stringify({
          admin_username:_this.user.username,
          admin_password:_this.user.password,
        }),
        headers:{
          Authorization:"Bearer pojroewtoe2d6vr93bxpf89kf1656qy4",
          "content-type": "application/x-www-form-urlencoded",
        }
      }).then( res => {
        console.log(res.code)
        if(res.code === 1 ){
          ipcRenderer.send('login-success',res.data)
        } else {
          _this.$message.error('帐号或密码错误');return;
        }
      }).catch(error => {
        _this.$message.error('接口请求错误');return;
      })
    }
  }
}
</script>

<style scoped>
.login {
  height: 100%;
  width: 100%;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
}
.login .center {
  padding: 25px;
  min-width: 370px;
}
.login .center h1 {
  color: #66a6ff;
  font-weight: bold;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  align-content: center;
  padding-bottom: 25px;
  text-align: center;
  -webkit-animation: moveTopBottom 2s linear forwards;
  animation: moveTopBottom 2s linear forwards;
  font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
}

.login .center .logo{
  width: 64px;
  height: 64px;
  background: url("") no-repeat;
  background-size: cover;
}

.login .center .inputLi {
  margin-bottom: 15px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
}
.login .center .inputLi input {
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
  border: 1px solid #ddd;
  height: 45px;
  padding: 0 10px 0 40px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  color: #66a6ff;
  font-size: 18px;
  outline: none;
}
.login .center .inputLi input::-webkit-input-placeholder {
  color: #999;
  font-size: 12px;
}
.login .center .inputLi input:-ms-input-placeholder {
  color: #999;
  font-size: 12px;
}
.login .center .inputLi input::-ms-input-placeholder {
  color: #999;
  font-size: 12px;
}
.login .center .inputLi input::placeholder {
  color: #999;
  font-size: 12px;
}
.login .center .inputLi input:focus {
  border: 1px solid #66a6ff;
}
.login .center .inputLi .user {
  background: #fff url("") left 10px center no-repeat;
  background-size: 20px 20px;
}
.login .center .inputLi .pwd {
  background: #fff url("") left 10px center no-repeat;
  background-size: 20px 20px;
}
.login .center .inputLi button {
  background-image: -webkit-gradient(linear, left bottom, left top, from(#09203f), to(#537895));
  background-image: linear-gradient(to top, #09203f 0%, #537895 100%);
  border: none;
  height: 45px;
  color: #fff;
  outline: none;
  font-weight: bold;
  letter-spacing: 3px;
  font-family: "微软雅黑";
  font-size: 18px;
  cursor: pointer;
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
}
.login .center .inputLi button:active {
  opacity: 0.8;
}
.login .center .tip {
  font-size: 12px;
  color: #999;
}
@-webkit-keyframes moveTopBottom {
  0% {
    -webkit-filter: grayscale(100%);
    filter: grayscale(100%);
  }
  20% {
    -webkit-filter: grayscale(80%);
    filter: grayscale(80%);
  }
  40% {
    -webkit-filter: grayscale(60%);
    filter: grayscale(60%);
  }
  60% {
    -webkit-filter: grayscale(40%);
    filter: grayscale(40%);
  }
  80% {
    -webkit-filter: grayscale(20%);
    filter: grayscale(20%);
  }
  100% {
    -webkit-filter: grayscale(0%);
    filter: grayscale(0%);
  }
}
@keyframes moveTopBottom {
  0% {
    -webkit-filter: grayscale(100%);
    filter: grayscale(100%);
  }
  20% {
    -webkit-filter: grayscale(80%);
    filter: grayscale(80%);
  }
  40% {
    -webkit-filter: grayscale(60%);
    filter: grayscale(60%);
  }
  60% {
    -webkit-filter: grayscale(40%);
    filter: grayscale(40%);
  }
  80% {
    -webkit-filter: grayscale(20%);
    filter: grayscale(20%);
  }
  100% {
    -webkit-filter: grayscale(0%);
    filter: grayscale(0%);
  }
}
</style>
